import { System } from "./System";
import { b2Contact, b2ContactImpulse, b2ContactListener, b2Manifold, b2ParticleBodyContact, b2ParticleContact, b2ParticleSystem, b2Shape } from "@flyover/box2d";
import { PhysicsSystem } from "../../PhysicsSystem";
import { getGameObjectById } from "../../engine";


export class GamePlaySystem extends System implements b2ContactListener{


    
    public BeginContact(contact: b2Contact<b2Shape, b2Shape>): void {

        const bodyA = contact.GetFixtureA().GetBody().GetUserData();
        const bodyB = contact.GetFixtureB().GetBody().GetUserData();
        //碰撞portal场景转换（还要补充和dialog之间的关系）

        if (bodyA.id==='Alice' && bodyB.id==='potion2' || bodyA.id==='potion2' && bodyB.id==='Alice') {
            const parent = this.rootGameObject
            const potion2=getGameObjectById('potion2')
            parent.removeChild(potion2)
        }
        

    }
    public EndContact(contact: b2Contact<b2Shape, b2Shape>): void {
    }
    public PreSolve(contact: b2Contact<b2Shape, b2Shape>, oldManifold: b2Manifold): void {
    }
    public PostSolve(contact: b2Contact<b2Shape, b2Shape>, impulse: b2ContactImpulse): void {
    }




    public BeginContactFixtureParticle(system: b2ParticleSystem, contact: b2ParticleBodyContact): void {
    }
    public EndContactFixtureParticle(system: b2ParticleSystem, contact: b2ParticleBodyContact): void {
    }
    public BeginContactParticleParticle(system: b2ParticleSystem, contact: b2ParticleContact): void {
    }
    public EndContactParticleParticle(system: b2ParticleSystem, contact: b2ParticleContact): void {
    }

    onStart(): void {
        console.log('开始游戏')

        this.gameEngine.getSystem(PhysicsSystem).SetContactListener(this)
    }

    onUpdate(): void {

    }
}